%%% Copyright 2010 Google Inc.
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
%%% You may obtain a copy of the License at
%%%
%%%     http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing, software
%%% distributed under the License is distributed on an "AS IS" BASIS,
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%%% See the License for the specific language governing permissions and
%%% limitations under the License.

%%% @copyright 2010 Google Inc. All Rights Reserved.
%%% @author <jacoby@google.com> Jacoby Thwaites [http://sites/madcloud]
%%% @version {@version}
%%% @doc
%%% httpd-callback client for web and foreign-language clients.
%%%
%%% The web client provides HTTP GET/POST analogs for the view_fsm client
%%% functions.
%%%
%%% @headerfile "../include/txm.hrl"

-module(web_view).

-include("txm.hrl").

-export([start_view/3]).

%% @doc Handles start request by starting a view_fsm and placing the
%% sessionId in the client data.
%% @spec start_view(term(), list(), list()) -> ok
start_view(SessionId, _Env, Input) ->
  Args = web_util:query2proplist(Input),
  try
    {ok, V} = view_fsm:start(?MODULE, SessionId),
    web_util:send_response(Args, SessionId, {start_view, [{view, V}]})
  catch
    Fault:Reason ->
      ?ERROR([{Fault, Reason}]),
      web_util:send_response(Args, SessionId, {error, Args})
  end.
